package com.quick.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.quick.base.Page;
import com.quick.base.Search;
import com.quick.mapper.SysPostMapper;
import com.quick.service.ISysPostService;
import com.quick.sys.domain.dto.SysPostDTO;
import com.quick.sys.domain.pojo.SysPost;
import com.quick.sys.domain.search.SysPostSearch;
import com.quick.sys.domain.vo.SysPostVo;
import com.quick.util.Convert;
import com.quick.util.PageUtil;
import com.quick.util.QuickTool;

import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@AllArgsConstructor
public class SysPostServiceImpl implements ISysPostService {

    private final SysPostMapper sysPostMapper;
    @Override
    public Page<SysPostVo> search(Search<SysPostSearch> search) {
        PageHelper.startPage(search.getPageNum(),search.getPageSize());
        QueryWrapper<SysPost> queryWrapper = new QueryWrapper<>();
        queryWrapper(queryWrapper, search.getSearch());
        List<SysPost> list = sysPostMapper.selectList(queryWrapper);
        PageInfo<SysPost> pageInfo = new PageInfo<>(list);
        return PageUtil.page(pageInfo,SysPostVo.class);
    }
	@Override
	public Boolean saveSysPost(SysPostDTO role) {
		SysPost entity = Convert.convert(role, SysPost.class);
		if(QuickTool.isNull(role.getId())) {
			QuickTool.setFillInsert(entity);
			return sysPostMapper.insert(entity)>0;
		}
		QuickTool.setFillUpdate(entity);
		return sysPostMapper.updateById(entity)>0;
	}
	@Override
	public SysPostVo queryById(Long id) {
		SysPost original= sysPostMapper.selectById(id);
		return Convert.convert(original, SysPostVo.class);
	}
	@Override
	public Boolean delById(Long id) {
		return sysPostMapper.deleteById(id)>0;
	}
	@Override
	public Boolean batchDel(List<Long> ids) {
		return sysPostMapper.deleteBatchIds(ids)>0;
	}
}
